package com.example.fairytset;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;

public class HeadFragment extends Fragment implements View.OnClickListener,ViewPager.OnPageChangeListener {

    private TextView atx1;
    private TextView atx2;
    private TextView atx3;
    private ViewPager vpager;

    private MyFragmentPagerAdapter mAdapter;

    public static final int PAGE_ONE = 0;
    public static final int PAGE_TWO = 1;
    public static final int PAGE_THREE = 2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.headportrait, container, false);
        mAdapter = new MyFragmentPagerAdapter(getFragmentManager());
        bindviews(view);
        return view;
    }

    private void bindviews(View view) {
        atx1 = view.findViewById(R.id.atx1);
        atx2 = view.findViewById(R.id.atx2);
        atx3 = view.findViewById(R.id.atx3);
        vpager = view.findViewById(R.id.vpager);
        vpager.setAdapter(mAdapter);
        vpager.setCurrentItem(2);
        atx1.setOnClickListener(this);
        atx2.setOnClickListener(this);
        atx3.setOnClickListener(this);
        vpager.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.atx1:
                vpager.setCurrentItem(PAGE_ONE);
                break;
            case R.id.atx2:
                vpager.setCurrentItem(PAGE_TWO);
                break;
            case R.id.atx3:
                vpager.setCurrentItem(PAGE_THREE);
                break;
        }

    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    }

    @Override
    public void onPageSelected(int position) {
    }

    @Override
    public void onPageScrollStateChanged(int state) {
        //state的状态有三个，0表示什么都没做，1正在滑动，2滑动完毕
//        if (state == 2) {
//            switch (vpager.getCurrentItem()) {
//                case PAGE_ONE:
//                    atx1.set(true);
//                    break;
//                case PAGE_TWO:
//                    atx2.setChecked(true);
//                    break;
//                case PAGE_THREE:
//                    atx3.setChecked(true);
//                    break;
//            }
//        }
    }
}
